<template>
  <div class="home">
    <van-swipe :autoplay="3000" lazy-render>
      <van-swipe-item v-for="(item, index) in images" :key="index">
        <img :src="'http://47.102.145.189:8009' + item.imgSrc" alt="" />
      </van-swipe-item>
    </van-swipe>

    <div class="home-one">
      <div class="searchs">
        <span
          ><router-link to="/CityList">{{ areaList.label }}</router-link
          ><van-icon name="location"
        /></span>
        <span>|</span>
        <span
          ><van-icon name="search" /><input
            type="text"
            placeholder="请输入小区或地址"
        /></span>
      </div>
      <van-icon name="location-o" @click="gomap" />
    </div>

    <div class="home-two">
      <router-link to="/List"
        ><van-icon name="wap-home-o" /><span>整租</span></router-link
      >
      <router-link to="/List"
        ><van-icon name="friends-o" /><span>合租</span></router-link
      >
      <router-link to="/Map"
        ><van-icon name="location-o" /><span>地图找房</span></router-link
      >
      <router-link to="/Rent/Add"
        ><van-icon name="home-o" /><span>去出租</span></router-link
      >
    </div>

    <div class="home-three">
      <h3>租房小组</h3>
      <span>更多</span>
    </div>

    <div class="home-four">
      <div
        class="home-four-one"
        v-for="(item, index) in synchysis"
        :key="index"
      >
        <dl>
          <dd>
            <p>{{ item.title }}</p>
            <p>{{ item.desc }}</p>
          </dd>
          <dt>
            <img :src="'http://47.102.145.189:8009' + item.imgSrc" alt="" />
          </dt>
        </dl>
      </div>
    </div>

    <div class="home-five">
      <h3>最新资讯</h3>
    </div>

    <div class="home-six">
      <div class="home-six-one" v-for="(v, i) in latestnews" :key="i">
        <dl>
          <dt><img :src="'http://47.102.145.189:8009' + v.imgSrc" alt="" /></dt>
          <dd>
            <p>{{ v.title }}</p>
            <p>
              <span>{{ v.from }}</span>
              <span>{{ v.date }}</span>
            </p>
          </dd>
        </dl>
      </div>
    </div>
  </div>
</template>

<script>
import { mapState } from "vuex";
export default {
  data() {
    return {
      images: [],
      synchysis: [],
      latestnews: [],
    };
  },

  computed: {
    ...mapState(["areaList"]),
  },
  // mounted() {
  //   function myFun(result) {
  //     var cityName = result.name;
  //     alert("当前定位城市:" + cityName);
  //     this.area(cityName);
  //   }
  //   var myCity = new BMap.LocalCity();
  //   myCity.get(myFun);
  // },
  methods: {
    //轮播图
    swiper() {
      this.$http.get("/home/swiper").then((res) => {
        console.log(res);
        this.images = res.data.body;
        console.log(this.images);
      });
    },

    //租房小组
    synchy() {
      this.$http.get("/home/groups").then((res) => {
        console.log(res);
        this.synchysis = res.data.body;
        console.log(this.synchysis);
      });
    },

    //最新资讯
    latest() {
      this.$http.get("/home/news").then((res) => {
        console.log(res);
        this.latestnews = res.data.body;
        console.log(this.latestnews);
      });
    },

    gomap() {
      this.$router.push("/Map");
    },
  },
  created() {
    this.swiper();
    this.synchy();
    this.latest();
  },
};
</script>

<style>
.home {
  width: 100%;
  height: 100%;
  background: #e6e6e6;
}
.van-swipe {
  width: 100%;
  height: 200px;
  position: relative;
}
.van-swipe img {
  width: 100%;
  height: 100%;
}
.home-one {
  width: 100%;
  height: 35px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: absolute;
  left: 0;
  top: 1%;
  padding: 0 15px;
}
.home-one i {
  font-size: 14px;
}
.searchs {
  height: 30px;
  flex: 1;
  background: #fff;
  border-radius: 4px;
  display: flex;
  align-items: center;
  margin: 0 5px;
  font-size: 14px;
}
.searchs input {
  border: none;
  width: 100%;
}
.searchs span:nth-child(1) {
  margin: 0 15px;
}
.searchs span:nth-child(3) {
  display: flex;
  margin: 0 15px;
  justify-content: center;
  align-items: center;
}
.home-two {
  width: 100%;
  height: 80px;
  display: flex;
  flex-wrap: wrap;
  text-align: center;
  align-items: center;
  background: #fff;
}
.home-two a {
  width: calc(100% / 4);
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 40px;
  color: black;
  font-size: 14px;
}
.home-two a i {
  width: 35px;
  height: 35px;
  line-height: 35px;
  border: 1px solid greenyellow;
  border-radius: 40px;
  color: greenyellow;
}
.home-three {
  width: 100%;
  height: 30px;
  padding: 0 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 14px;
}
.home-three span {
  color: #ccc;
}
.home-four {
  width: 100%;
  height: 180px;
  display: flex;
  flex-wrap: wrap;
  text-align: center;
  justify-content: space-between;
  padding: 0 10px;
}
.home-four-one {
  width: 48%;
  height: 80px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #fff;
  margin: 5px 0;
  padding: 0 5px;
}
.home-four-one dl {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.home-four-one dl dd {
  font-size: 14px;
}
.home-four-one dl dt img {
  width: 55px;
  height: 55px;
}
.home-five {
  width: 100%;
  height: 30px;
  display: flex;
  align-items: center;
  padding: 0 10px;
  font-size: 14px;
}
.home-six {
  width: 100%;
  height: 360px;
  background: #fff;
}
.home-six-one {
  width: 100%;
  height: 120px;
  padding: 0 10px;
  border-bottom: 1px solid #e6e6e6;
}
.home-six-one dl {
  width: 100%;
  height: 120px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.home-six-one dl dt {
  width: 120px;
  height: 90px;
}
.home-six-one dl dt img {
  width: 100%;
  height: 100%;
}
.home-six-one dl dd {
  width: 345px;
  height: 90px;
  padding-left: 20px;
  font-size: 16px;
}
.home-six-one dl dd p:nth-child(2) {
  margin-top: 30px;
  display: flex;
  justify-content: space-between;
}
</style>